package com.example.demo.controller;

import com.port.fee.common.Result;
import com.port.fee.dto.LoginDTO;
import com.port.fee.entity.AdminUser;
import com.port.fee.service.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理员用户控制器
 */
@RestController
@RequestMapping("/admin")
@Tag(name = "管理员管理", description = "管理员相关接口")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    /**
     * 登录
     */
    @PostMapping("/login")
    @Operation(summary = "管理员登录", description = "用户名密码登录")
    public Result<Map<String, Object>> login(@RequestBody LoginDTO loginDTO) {
        AdminUser adminUser = adminUserService.login(loginDTO.getUsername(), loginDTO.getPassword());
        
        if (adminUser != null) {
            Map<String, Object> data = new HashMap<>();
            data.put("adminId", adminUser.getAdminId());
            data.put("username", adminUser.getUsername());
            data.put("realName", adminUser.getRealName());
            
            // 简单模拟一个token
            String token = "admin-token-" + System.currentTimeMillis();
            data.put("token", token);
            
            return Result.success(data, "登录成功");
        } else {
            return Result.failed("用户名或密码错误");
        }
    }
} 